#pragma once
// MESSAGE MOTOR_CTRL PACKING

#define MAVLINK_MSG_ID_MOTOR_CTRL 180

MAVPACKED(
typedef struct __mavlink_motor_ctrl_t {
 float pos; /*<  motor position*/
 float pos1; /*<  motor position*/
 float res1; /*<  res1*/
 float res2; /*<  res2*/
 uint8_t cmd; /*<  commands*/
 uint8_t addr; /*<  motor number*/
}) mavlink_motor_ctrl_t;

#define MAVLINK_MSG_ID_MOTOR_CTRL_LEN 18
#define MAVLINK_MSG_ID_MOTOR_CTRL_MIN_LEN 18
#define MAVLINK_MSG_ID_180_LEN 18
#define MAVLINK_MSG_ID_180_MIN_LEN 18

#define MAVLINK_MSG_ID_MOTOR_CTRL_CRC 230
#define MAVLINK_MSG_ID_180_CRC 230



#if MAVLINK_COMMAND_24BIT
#define MAVLINK_MESSAGE_INFO_MOTOR_CTRL { \
    180, \
    "MOTOR_CTRL", \
    6, \
    {  { "cmd", NULL, MAVLINK_TYPE_UINT8_T, 0, 16, offsetof(mavlink_motor_ctrl_t, cmd) }, \
         { "addr", NULL, MAVLINK_TYPE_UINT8_T, 0, 17, offsetof(mavlink_motor_ctrl_t, addr) }, \
         { "pos", NULL, MAVLINK_TYPE_FLOAT, 0, 0, offsetof(mavlink_motor_ctrl_t, pos) }, \
         { "pos1", NULL, MAVLINK_TYPE_FLOAT, 0, 4, offsetof(mavlink_motor_ctrl_t, pos1) }, \
         { "res1", NULL, MAVLINK_TYPE_FLOAT, 0, 8, offsetof(mavlink_motor_ctrl_t, res1) }, \
         { "res2", NULL, MAVLINK_TYPE_FLOAT, 0, 12, offsetof(mavlink_motor_ctrl_t, res2) }, \
         } \
}
#else
#define MAVLINK_MESSAGE_INFO_MOTOR_CTRL { \
    "MOTOR_CTRL", \
    6, \
    {  { "cmd", NULL, MAVLINK_TYPE_UINT8_T, 0, 16, offsetof(mavlink_motor_ctrl_t, cmd) }, \
         { "addr", NULL, MAVLINK_TYPE_UINT8_T, 0, 17, offsetof(mavlink_motor_ctrl_t, addr) }, \
         { "pos", NULL, MAVLINK_TYPE_FLOAT, 0, 0, offsetof(mavlink_motor_ctrl_t, pos) }, \
         { "pos1", NULL, MAVLINK_TYPE_FLOAT, 0, 4, offsetof(mavlink_motor_ctrl_t, pos1) }, \
         { "res1", NULL, MAVLINK_TYPE_FLOAT, 0, 8, offsetof(mavlink_motor_ctrl_t, res1) }, \
         { "res2", NULL, MAVLINK_TYPE_FLOAT, 0, 12, offsetof(mavlink_motor_ctrl_t, res2) }, \
         } \
}
#endif

/**
 * @brief Pack a motor_ctrl message
 * @param system_id ID of this system
 * @param component_id ID of this component (e.g. 200 for IMU)
 * @param msg The MAVLink message to compress the data into
 *
 * @param cmd  commands
 * @param addr  motor number
 * @param pos  motor position
 * @param pos1  motor position
 * @param res1  res1
 * @param res2  res2
 * @return length of the message in bytes (excluding serial stream start sign)
 */
static inline uint16_t mavlink_msg_motor_ctrl_pack(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg,
                               uint8_t cmd, uint8_t addr, float pos, float pos1, float res1, float res2)
{
#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS
    char buf[MAVLINK_MSG_ID_MOTOR_CTRL_LEN];
    _mav_put_float(buf, 0, pos);
    _mav_put_float(buf, 4, pos1);
    _mav_put_float(buf, 8, res1);
    _mav_put_float(buf, 12, res2);
    _mav_put_uint8_t(buf, 16, cmd);
    _mav_put_uint8_t(buf, 17, addr);

        memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, MAVLINK_MSG_ID_MOTOR_CTRL_LEN);
#else
    mavlink_motor_ctrl_t packet;
    packet.pos = pos;
    packet.pos1 = pos1;
    packet.res1 = res1;
    packet.res2 = res2;
    packet.cmd = cmd;
    packet.addr = addr;

        memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, MAVLINK_MSG_ID_MOTOR_CTRL_LEN);
#endif

    msg->msgid = MAVLINK_MSG_ID_MOTOR_CTRL;
    return mavlink_finalize_message(msg, system_id, component_id, MAVLINK_MSG_ID_MOTOR_CTRL_MIN_LEN, MAVLINK_MSG_ID_MOTOR_CTRL_LEN, MAVLINK_MSG_ID_MOTOR_CTRL_CRC);
}

/**
 * @brief Pack a motor_ctrl message on a channel
 * @param system_id ID of this system
 * @param component_id ID of this component (e.g. 200 for IMU)
 * @param chan The MAVLink channel this message will be sent over
 * @param msg The MAVLink message to compress the data into
 * @param cmd  commands
 * @param addr  motor number
 * @param pos  motor position
 * @param pos1  motor position
 * @param res1  res1
 * @param res2  res2
 * @return length of the message in bytes (excluding serial stream start sign)
 */
static inline uint16_t mavlink_msg_motor_ctrl_pack_chan(uint8_t system_id, uint8_t component_id, uint8_t chan,
                               mavlink_message_t* msg,
                                   uint8_t cmd,uint8_t addr,float pos,float pos1,float res1,float res2)
{
#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS
    char buf[MAVLINK_MSG_ID_MOTOR_CTRL_LEN];
    _mav_put_float(buf, 0, pos);
    _mav_put_float(buf, 4, pos1);
    _mav_put_float(buf, 8, res1);
    _mav_put_float(buf, 12, res2);
    _mav_put_uint8_t(buf, 16, cmd);
    _mav_put_uint8_t(buf, 17, addr);

        memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, MAVLINK_MSG_ID_MOTOR_CTRL_LEN);
#else
    mavlink_motor_ctrl_t packet;
    packet.pos = pos;
    packet.pos1 = pos1;
    packet.res1 = res1;
    packet.res2 = res2;
    packet.cmd = cmd;
    packet.addr = addr;

        memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, MAVLINK_MSG_ID_MOTOR_CTRL_LEN);
#endif

    msg->msgid = MAVLINK_MSG_ID_MOTOR_CTRL;
    return mavlink_finalize_message_chan(msg, system_id, component_id, chan, MAVLINK_MSG_ID_MOTOR_CTRL_MIN_LEN, MAVLINK_MSG_ID_MOTOR_CTRL_LEN, MAVLINK_MSG_ID_MOTOR_CTRL_CRC);
}

/**
 * @brief Encode a motor_ctrl struct
 *
 * @param system_id ID of this system
 * @param component_id ID of this component (e.g. 200 for IMU)
 * @param msg The MAVLink message to compress the data into
 * @param motor_ctrl C-struct to read the message contents from
 */
static inline uint16_t mavlink_msg_motor_ctrl_encode(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, const mavlink_motor_ctrl_t* motor_ctrl)
{
    return mavlink_msg_motor_ctrl_pack(system_id, component_id, msg, motor_ctrl->cmd, motor_ctrl->addr, motor_ctrl->pos, motor_ctrl->pos1, motor_ctrl->res1, motor_ctrl->res2);
}

/**
 * @brief Encode a motor_ctrl struct on a channel
 *
 * @param system_id ID of this system
 * @param component_id ID of this component (e.g. 200 for IMU)
 * @param chan The MAVLink channel this message will be sent over
 * @param msg The MAVLink message to compress the data into
 * @param motor_ctrl C-struct to read the message contents from
 */
static inline uint16_t mavlink_msg_motor_ctrl_encode_chan(uint8_t system_id, uint8_t component_id, uint8_t chan, mavlink_message_t* msg, const mavlink_motor_ctrl_t* motor_ctrl)
{
    return mavlink_msg_motor_ctrl_pack_chan(system_id, component_id, chan, msg, motor_ctrl->cmd, motor_ctrl->addr, motor_ctrl->pos, motor_ctrl->pos1, motor_ctrl->res1, motor_ctrl->res2);
}

/**
 * @brief Send a motor_ctrl message
 * @param chan MAVLink channel to send the message
 *
 * @param cmd  commands
 * @param addr  motor number
 * @param pos  motor position
 * @param pos1  motor position
 * @param res1  res1
 * @param res2  res2
 */
#ifdef MAVLINK_USE_CONVENIENCE_FUNCTIONS

static inline void mavlink_msg_motor_ctrl_send(mavlink_channel_t chan, uint8_t cmd, uint8_t addr, float pos, float pos1, float res1, float res2)
{
#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS
    char buf[MAVLINK_MSG_ID_MOTOR_CTRL_LEN];
    _mav_put_float(buf, 0, pos);
    _mav_put_float(buf, 4, pos1);
    _mav_put_float(buf, 8, res1);
    _mav_put_float(buf, 12, res2);
    _mav_put_uint8_t(buf, 16, cmd);
    _mav_put_uint8_t(buf, 17, addr);

    _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_MOTOR_CTRL, buf, MAVLINK_MSG_ID_MOTOR_CTRL_MIN_LEN, MAVLINK_MSG_ID_MOTOR_CTRL_LEN, MAVLINK_MSG_ID_MOTOR_CTRL_CRC);
#else
    mavlink_motor_ctrl_t packet;
    packet.pos = pos;
    packet.pos1 = pos1;
    packet.res1 = res1;
    packet.res2 = res2;
    packet.cmd = cmd;
    packet.addr = addr;

    _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_MOTOR_CTRL, (const char *)&packet, MAVLINK_MSG_ID_MOTOR_CTRL_MIN_LEN, MAVLINK_MSG_ID_MOTOR_CTRL_LEN, MAVLINK_MSG_ID_MOTOR_CTRL_CRC);
#endif
}

/**
 * @brief Send a motor_ctrl message
 * @param chan MAVLink channel to send the message
 * @param struct The MAVLink struct to serialize
 */
static inline void mavlink_msg_motor_ctrl_send_struct(mavlink_channel_t chan, const mavlink_motor_ctrl_t* motor_ctrl)
{
#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS
    mavlink_msg_motor_ctrl_send(chan, motor_ctrl->cmd, motor_ctrl->addr, motor_ctrl->pos, motor_ctrl->pos1, motor_ctrl->res1, motor_ctrl->res2);
#else
    _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_MOTOR_CTRL, (const char *)motor_ctrl, MAVLINK_MSG_ID_MOTOR_CTRL_MIN_LEN, MAVLINK_MSG_ID_MOTOR_CTRL_LEN, MAVLINK_MSG_ID_MOTOR_CTRL_CRC);
#endif
}

#if MAVLINK_MSG_ID_MOTOR_CTRL_LEN <= MAVLINK_MAX_PAYLOAD_LEN
/*
  This varient of _send() can be used to save stack space by re-using
  memory from the receive buffer.  The caller provides a
  mavlink_message_t which is the size of a full mavlink message. This
  is usually the receive buffer for the channel, and allows a reply to an
  incoming message with minimum stack space usage.
 */
static inline void mavlink_msg_motor_ctrl_send_buf(mavlink_message_t *msgbuf, mavlink_channel_t chan,  uint8_t cmd, uint8_t addr, float pos, float pos1, float res1, float res2)
{
#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS
    char *buf = (char *)msgbuf;
    _mav_put_float(buf, 0, pos);
    _mav_put_float(buf, 4, pos1);
    _mav_put_float(buf, 8, res1);
    _mav_put_float(buf, 12, res2);
    _mav_put_uint8_t(buf, 16, cmd);
    _mav_put_uint8_t(buf, 17, addr);

    _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_MOTOR_CTRL, buf, MAVLINK_MSG_ID_MOTOR_CTRL_MIN_LEN, MAVLINK_MSG_ID_MOTOR_CTRL_LEN, MAVLINK_MSG_ID_MOTOR_CTRL_CRC);
#else
    mavlink_motor_ctrl_t *packet = (mavlink_motor_ctrl_t *)msgbuf;
    packet->pos = pos;
    packet->pos1 = pos1;
    packet->res1 = res1;
    packet->res2 = res2;
    packet->cmd = cmd;
    packet->addr = addr;

    _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_MOTOR_CTRL, (const char *)packet, MAVLINK_MSG_ID_MOTOR_CTRL_MIN_LEN, MAVLINK_MSG_ID_MOTOR_CTRL_LEN, MAVLINK_MSG_ID_MOTOR_CTRL_CRC);
#endif
}
#endif

#endif

// MESSAGE MOTOR_CTRL UNPACKING


/**
 * @brief Get field cmd from motor_ctrl message
 *
 * @return  commands
 */
static inline uint8_t mavlink_msg_motor_ctrl_get_cmd(const mavlink_message_t* msg)
{
    return _MAV_RETURN_uint8_t(msg,  16);
}

/**
 * @brief Get field addr from motor_ctrl message
 *
 * @return  motor number
 */
static inline uint8_t mavlink_msg_motor_ctrl_get_addr(const mavlink_message_t* msg)
{
    return _MAV_RETURN_uint8_t(msg,  17);
}

/**
 * @brief Get field pos from motor_ctrl message
 *
 * @return  motor position
 */
static inline float mavlink_msg_motor_ctrl_get_pos(const mavlink_message_t* msg)
{
    return _MAV_RETURN_float(msg,  0);
}

/**
 * @brief Get field pos1 from motor_ctrl message
 *
 * @return  motor position
 */
static inline float mavlink_msg_motor_ctrl_get_pos1(const mavlink_message_t* msg)
{
    return _MAV_RETURN_float(msg,  4);
}

/**
 * @brief Get field res1 from motor_ctrl message
 *
 * @return  res1
 */
static inline float mavlink_msg_motor_ctrl_get_res1(const mavlink_message_t* msg)
{
    return _MAV_RETURN_float(msg,  8);
}

/**
 * @brief Get field res2 from motor_ctrl message
 *
 * @return  res2
 */
static inline float mavlink_msg_motor_ctrl_get_res2(const mavlink_message_t* msg)
{
    return _MAV_RETURN_float(msg,  12);
}

/**
 * @brief Decode a motor_ctrl message into a struct
 *
 * @param msg The message to decode
 * @param motor_ctrl C-struct to decode the message contents into
 */
static inline void mavlink_msg_motor_ctrl_decode(const mavlink_message_t* msg, mavlink_motor_ctrl_t* motor_ctrl)
{
#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS
    motor_ctrl->pos = mavlink_msg_motor_ctrl_get_pos(msg);
    motor_ctrl->pos1 = mavlink_msg_motor_ctrl_get_pos1(msg);
    motor_ctrl->res1 = mavlink_msg_motor_ctrl_get_res1(msg);
    motor_ctrl->res2 = mavlink_msg_motor_ctrl_get_res2(msg);
    motor_ctrl->cmd = mavlink_msg_motor_ctrl_get_cmd(msg);
    motor_ctrl->addr = mavlink_msg_motor_ctrl_get_addr(msg);
#else
        uint8_t len = msg->len < MAVLINK_MSG_ID_MOTOR_CTRL_LEN? msg->len : MAVLINK_MSG_ID_MOTOR_CTRL_LEN;
        memset(motor_ctrl, 0, MAVLINK_MSG_ID_MOTOR_CTRL_LEN);
    memcpy(motor_ctrl, _MAV_PAYLOAD(msg), len);
#endif
}
